/**
 * @Author MrLi
 * @Version 1.0
 * @Date 2023-08-15 13:00:24
 */
package com.cl.erp_2301.Service.impl;

import com.cl.erp_2301.Service.EmpRoleService;
import com.cl.erp_2301.Service.EmpService;
import com.cl.erp_2301.dto.EmpDTO;
import com.cl.erp_2301.dto.MenuDTO;
import com.cl.erp_2301.mapper.EmpMapper;
import com.cl.erp_2301.mapper.EmpRoleMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EmpRoleServiceImpl implements EmpRoleService {

    @Resource
    private EmpRoleMapper empRoleMapper;

    @Override
    public List<EmpDTO> findByN(String name) {
        return empRoleMapper.findByN(name);
    }

    @Override
    public void updateId(EmpDTO empRoleDTO) {
        empRoleMapper.updateId(empRoleDTO);
    }

    @Override
    public void deleteById(Integer id) {
        empRoleMapper.deleteById(id);
    }

    @Override
    public int addRole(EmpDTO empRoleDTO) {
        return empRoleMapper.addRole(empRoleDTO);
    }

    @Override
    public List<EmpDTO> findEmp() {
        return empRoleMapper.findEmp();
    }

    @Override
    public List<MenuDTO> findByMen(Integer uuid) {
        List<MenuDTO> menuDTOList = empRoleMapper.findByMen(uuid);
        return menuDTOList;
    }

    @Override
    public List<MenuDTO> unKnow(int uuid) {
        List<MenuDTO> menuDTOList = empRoleMapper.unKnow(uuid);
        List<MenuDTO> newList = new ArrayList<MenuDTO>();
        for (MenuDTO menu : menuDTOList) {
            if (menu.getPid().equals(0)) {
                newList.add(menu);
            }
        }
        for (MenuDTO parentMenu : newList) {
            parentMenu.setList(new ArrayList<>());
            for (MenuDTO menu : menuDTOList) {
                if (menu.getPid() == parentMenu.getId()) {
                    parentMenu.getList().add(menu);
                }
            }
        }

        return newList;
    }

}
